﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL.Artwork;
using BLL.Project;
using BLL.ArtworkLike;
using BLL.User;

namespace WebApplication
{
    public partial class Default1 : System.Web.UI.Page
    {
        private ArtworkService artworkService = new ArtworkService();
        private ProjectService projectService = new ProjectService();
        private UserService userService = new UserService();

        public List<Models.Artworks> artworks = null;
        public List<Models.Projects> projects = null;
        public List<Models.User> users = null;

        public string artworkOrderBy = "LikeCount Desc";

        private void HandleArtwork()
        {
            int totalCount = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["art"]))
            {
                artworkOrderBy = Request.QueryString["art"] + " Desc";
            }
            // Not Login
            if (Session["UID"] == null)
            {
                artworks = artworkService.GetList(ref totalCount,1, 12, artworkOrderBy);
                return;
            }
            int uid = Convert.ToInt32(Session["UID"]);
            artworks = artworkService.GetList(ref totalCount,1, 12, artworkOrderBy);
            artworkService.QueryIsLiked(uid, artworks);
        }

        private void HandleProject()
        {
            int totalCount = 0;

            projects = projectService.GetList(ref totalCount, 1, 4, "CreatedAt Desc");
        }

        private void HandleUser()
        {
            int totalCount = 0;
            users = userService.GetList(ref totalCount);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            HandleProject();
            HandleArtwork();
            HandleUser();
        }
    }
}